<?php

namespace app\admin\controller\diy;

use app\common\controller\AdminController;
use app\common\model\DiyHome;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Log;

/**
 * @ControllerAnnotation(title="diy首页")
 */
class Home extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\common\model\DiyHome();
        
        $this->assign('getStatusList', $this->model->getStatusList());

    }
    public function index()
    {
        //获取列表
        try {
            $row = $this->model->getBaseByListAll();
        }catch (\Exception $e){
            $this->error("内部错误");
        }
        return $this->fetch('',[
            "row"=>$row
        ]);
    }

    /**
     * @Annotation(title="发布模板")
     * @return void
     */
    public function setRelease(){
        $id = $this->request->param('id',0,'intval');
        if($id == 0){
            $this->error("内部异常");
        }
        //设置发布状态
        try {
            $result = (new DiyHome())->setRelease($id);
        } catch (\Exception $exception) {
            Log::error($exception->getMessage()." ".$exception->getFile()." ".$exception->getLine());
            $this->error("错误");
        }
        if ($result) {
            $this->success("ok");
        }else{
            $this->error("操作失败");
        }
    }

}